package zky410;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class zky2 {
    public static void main(String[] args) throws IOException {
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(sc.readLine());
        int[][] num = new int[N][1];
        for (int i = 0; i < N; i++) {
            num[i][0] = Integer.parseInt(sc.readLine());
        }
        String result = result(num, N);
        System.out.println(result);
    }

    public static String result(int[][] num,int N){
        if(N == 0){
            return " "+0;
        }
        StringBuilder res = new StringBuilder();
        int res1 = 0;
        int start = 0;
        int end = 0;
        res.append(num[0][0]);
        for (int i = 1; i < N; i++) {
            if(i == start +60){
                res.append(","+num[i][0]);
                start = i;
            }
            if(num[i-1][0]-num[i][0]>=9){
                res1++;
            }else{
                if(res1 >= 4){
                    res1 = 4;
                    while(res1 >0 && i<N){
                        res.append(","+num[i][0]);
                        i++;
                        res1--;
                    }
                    i--;
                    start = i;
                    end = start+i;
                }
                res1 = 0;
            }
            if(res1==4){
                int temp = Math.max(end,i-7);
                while(temp <= i){

                    res.append(","+num[temp][0]);
                    temp++;
                }
            }
            if(res1>4){
                res.append(","+num[i][0]);
            }
        }return res.toString();
    }


}
